package edu.ilstu.mind.ise.ccp.module;

import edu.ilstu.mind.ise.ccp.logger.Logger;
import edu.ilstu.mind.ise.ccp.message.Message;
import edu.ilstu.mind.ise.ccp.message.MessageFactory;
import edu.ilstu.mind.ise.ccp.message.MessageSender;

/**
 * Interface for a module. A module connects to the CCP and is able to
 * send/receive messages.
 * 
 * @author Eric Thill
 * 
 */

public interface Module {
	/**
	 * Sets the {@link MessageFactory} that is used to create messages to be
	 * sent over the CCP. This method can only be called once and must be called
	 * before init().
	 * 
	 * @param messageFactory
	 */
	void setMessageFactory(MessageFactory messageFactory);

	/**
	 * Sets the {@link MessageSender} that is used to send messages via the CCP.
	 * This method can only be called once and must be called before init().
	 * 
	 * @param sender
	 *            The MessageSender
	 */
	void setMessageSender(MessageSender sender);

	/**
	 * Sets the {@link Logger}. This method can only be called once and must be
	 * called before init().
	 * 
	 * @param logger
	 *            The Logger
	 */
	void setLogger(Logger logger);

	/**
	 * Initialize method <br>
	 * Called after the {@link MessageSender} and {@link Logger} has been set
	 */
	void init();

	/**
	 * Called when a message has been received. <br>
	 * The calling thread will always be the same. This means that
	 * processMessage will not be called again until a previous call to this
	 * method has returned.
	 * 
	 * @param message
	 *            The received message
	 */
	void processMessage(Message message);
}
